import java.util.*;

class Person {
    int weight;
    int height;

    public Person(int weight,int height) {
        this.weight = weight;
        this.height = height;
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        while (s.hasNext()) {
            List<Person> res = new ArrayList<Person>();
            int n = s.nextInt();
            for(int i = 0; i < n; i++) {
                int num = s.nextInt();
                int weight = s.nextInt();
                int height = s.nextInt();
                Person p = new Person(weight,height);
                res.add(p);
            }
            Collections.sort(res, new Comparator<Person>() {
                @Override
                public int compare(Person o1, Person o2) {
                    int res1 = o1.height - o2.height;
                    if(res1 != 0) {
                        return res1;
                    }
                    return o1.weight - o2.weight;
                }
            });
            int[] dp = new int[n];
            Arrays.fill(dp,1);
            int max = 1;
            for(int i = 1; i < n; i++) {
                for(int j = i - 1; j >= 0; j--) {
                    if(res.get(i).weight > res.get(j).weight || (res.get(i).height == res.get(j).height && res.get(i).weight == res.get(j).weight)) {
                        dp[i] = Math.max(dp[i],dp[j] + 1);
                    }
                }
                max = Math.max(max,dp[i]);
            }
            System.out.println(max);
        }
    }
}